home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / asize / autosize.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-06  |  8.3 KB  |  236 lines

  1. VERSION 2.00
  2. Begin Form Autosize 
  3.    AutoRedraw      =   -1  'True
  4.    BackColor       =   &H00C0C0C0&
  5.    BorderStyle     =   3  'Fixed Double
  6.    Caption         =   "Autosize"
  7.    ClientHeight    =   3810
  8.    ClientLeft      =   2025
  9.    ClientTop       =   1830
  10.    ClientWidth     =   4470
  11.    Height          =   4215
  12.    Left            =   1965
  13.    LinkMode        =   1  'Source
  14.    LinkTopic       =   "Form1"
  15.    ScaleHeight     =   3810
  16.    ScaleWidth      =   4470
  17.    Top             =   1485
  18.    Width           =   4590
  19.    Begin Frame frmEd 
  20.       Caption         =   "frmEd"
  21.       Height          =   735
  22.       Left            =   1200
  23.       TabIndex        =   2
  24.       Top             =   2640
  25.       Width           =   1575
  26.       Begin OptionButton opt 
  27.          Caption         =   "Opt"
  28.          Height          =   255
  29.          Index           =   0
  30.          Left            =   360
  31.          TabIndex        =   3
  32.          Top             =   360
  33.          Width           =   855
  34.       End
  35.    End
  36.    Begin ListBox lst 
  37.       Height          =   810
  38.       Index           =   0
  39.       Left            =   1200
  40.       TabIndex        =   5
  41.       Top             =   1680
  42.       Width           =   2295
  43.    End
  44.    Begin ComboBox cbo 
  45.       Height          =   300
  46.       Index           =   0
  47.       Left            =   1200
  48.       Style           =   2  'Dropdown List
  49.       TabIndex        =   4
  50.       Top             =   1200
  51.       Width           =   2295
  52.    End
  53.    Begin TextBox txt 
  54.       Height          =   375
  55.       Index           =   0
  56.       Left            =   1200
  57.       TabIndex        =   0
  58.       Top             =   720
  59.       Width           =   1215
  60.    End
  61.    Begin CommandButton cmd 
  62.       Caption         =   "cmd"
  63.       Height          =   495
  64.       Index           =   0
  65.       Left            =   1200
  66.       TabIndex        =   1
  67.       TabStop         =   0   'False
  68.       Top             =   120
  69.       Width           =   1215
  70.    End
  71. Sub cmd_Click (Index As Integer)
  72.   Unload Autosize
  73. End Sub
  74. Sub DrawForm ()
  75.   '---Set textout alignment...
  76.   Result% = SetTextAlign(Autosize.hDC, TA_BOTTOM + TA_RIGHT)
  77.   '---Label 1...
  78.   SetFont 1, Autosize
  79.   Lbl$ = "Name: "
  80.   X% = txt(0).Left
  81.   Y% = txt(0).Top + txt(0).Height
  82.   Result% = TextOut(Autosize.hDC, X%, Y%, Lbl$, Len(Lbl$))
  83.   '---Label 2...
  84.   Lbl$ = "Address: "
  85.   Y% = txt(1).Top + txt(1).Height
  86.   Result% = TextOut(Autosize.hDC, X%, Y%, Lbl$, Len(Lbl$))
  87.   '---Label 3...
  88.   Lbl$ = "City, State & Zip: "
  89.   Y% = txt(2).Top + txt(2).Height
  90.   Result% = TextOut(Autosize.hDC, X%, Y%, Lbl$, Len(Lbl$))
  91.   '---Label 4...
  92.   Lbl$ = "Division: "
  93.   Y% = cbo(0).Top + cbo(0).Height
  94.   Result% = TextOut(Autosize.hDC, X%, Y%, Lbl$, Len(Lbl$))
  95.   '---Label 5...
  96.   Lbl$ = "Department: "
  97.   Y% = lst(0).Top + txt(0).Height
  98.   Result% = TextOut(Autosize.hDC, X%, Y%, Lbl$, Len(Lbl$))
  99. End Sub
  100. Sub Form_Load ()
  101.   Screen.MousePointer = 11
  102.   Refresh
  103.   Init_Measures Autosize
  104.   MakeForm
  105.   DrawForm
  106.   PrimeCtls
  107.   Screen.MousePointer = 0
  108. End Sub
  109. Sub MakeForm ()
  110.   '---------------------------------------------------------
  111.   '  Size & Position your controls.  Start in the upper
  112.   '  left of your form and work your way to the lower right.
  113.   '---------------------------------------------------------
  114.   '---------------------------------------------------
  115.   '  Create 2 additional Text boxes...
  116.   '---------------------------------------------------
  117.   For I% = 1 To 2
  118.     Load txt(I%)
  119.     txt(I%).Visible = -1
  120.   Next
  121.   '---------------------------------------------------
  122.   '  Move the highest textbox...
  123.   '  The left position of the textboxes will be the
  124.   '  width of the widest label printed on the form
  125.   '  PLUS 2 Std character widths.  Its' top will be 2
  126.   '  Std character heights from the top of the form.
  127.   '---------------------------------------------------
  128.   SetFont 1, Autosize
  129.   TheLft% = TextWidth("City, State & Zip: ") + 2 * gHStd
  130.   TheTop% = 2 * gVStd
  131.   '---Move is MUCH faster than setting the LEFT, TOP, WIDTH & HEIGHT properties.
  132.   txt(0).Move TheLft%, TheTop%, 25 * gHStd, gVStd
  133.   '---------------------------------------------------
  134.   '  Align the second textbox under the first...
  135.   '---------------------------------------------------
  136.   TheTop% = TheTop% + txt(0).Height + .5 * gVStd
  137.   txt(1).Move TheLft%, TheTop%, 25 * gHStd, gVStd
  138.   '---------------------------------------------------
  139.   '  Align the third textbox under the second...
  140.   '---------------------------------------------------
  141.   TheTop% = TheTop% + txt(0).Height + .5 * gVStd
  142.   txt(2).Move TheLft%, TheTop%, 25 * gHStd, gVStd
  143.   '---------------------------------------------------
  144.   '  Align the combo box under the last textbox...
  145.   '---------------------------------------------------
  146.   TheTop% = TheTop% + txt(0).Height + .5 * gVStd
  147.   cbo(0).Move TheLft%, TheTop%, 25 * gHStd
  148.   '---------------------------------------------------
  149.   '  Align the listbox under the combo box...
  150.   '  Make it 4 lines high.
  151.   '---------------------------------------------------
  152.   TheTop% = TheTop% + cbo(0).Height + .5 * gVStd
  153.   lst(0).Move TheLft%, TheTop%, 25 * gHStd, 4 * gVStd
  154.   '---------------------------------------------------
  155.   '  Size & Position option Frame...
  156.   '  Align the bottom of the frame with the bottom of
  157.   '  the listbox.  Put it 2 std character widths from
  158.   '  the right of the listbox.
  159.   '---------------------------------------------------
  160.   frmEd.Caption = "Education"
  161.   TheWth% = 15 * gHStd
  162.   TheHgt% = 6 * gVStd
  163.   TheLft% = lst(0).Left + lst(0).width + 2 * gHStd
  164.   TheTop% = lst(0).Top + lst(0).Height - TheHgt%
  165.   frmEd.Move TheLft%, TheTop%, TheWth%, TheHgt%
  166.   '---------------------------------------------------
  167.   '  Option buttons...
  168.   '  These are positioned relative to the walls of its
  169.   '  container (frame).  Since the scalemode of a frame
  170.   '  is always in Twips, we must use our gTwpsPerPxlX
  171.   '  and gTwpsPerPxlY global variables to multiply by.
  172.   '---------------------------------------------------
  173.   '---Load an additional option button, set properties...
  174.   Load opt(1)
  175.   opt(1).Visible = -1
  176.   opt(1).Caption = "College"
  177.   opt(0).Caption = "High School"
  178.   '---position & Size option buttons...
  179.   TheTop% = 2 * gVStd * gTwpsPerPxlY
  180.   TheLft% = 2 * gHStd * gTwpsPerPxlX
  181.   TheWth% = 12 * gHStd * gTwpsPerPxlX
  182.   TheHgt% = 1.5 * gVStd * gTwpsPerPxlY
  183.   opt(0).Move TheLft%, TheTop%, TheWth%, TheHgt%
  184.   opt(1).Move TheLft%, opt(0).Top + opt(0).Height, TheWth%, TheHgt%
  185.   '-------------------------------------------------------
  186.   '   Create required Command buttons and position them...
  187.   '-------------------------------------------------------
  188.   Load cmd(1)
  189.   cmd(1).Visible = -1
  190.   cmd(1).Cancel = -1
  191.   cmd(1).Caption = "Cancel"
  192.   cmd(0).Default = -1
  193.   cmd(0).Caption = "OK"
  194.   cmd(0).Move frmEd.Left + frmEd.width - 9 * gHStd%, txt(0).Top, 9 * gHStd, 1.85 * gVStd
  195.   cmd(1).Move cmd(0).Left, cmd(0).Top + 2.5 * gVStd, 9 * gHStd, 1.85 * gVStd
  196.   '-------------------
  197.   '  Set Tab Order...
  198.   '-------------------
  199.   txt(0).TabIndex = 0
  200.   txt(1).TabIndex = 1
  201.   txt(2).TabIndex = 2
  202.   cbo(0).TabIndex = 3
  203.   lst(0).TabIndex = 4
  204.   frmEd.TabIndex = 5
  205.   '---------------------------------
  206.   '   Size & Position the Form...
  207.   '---------------------------------
  208.   '---Make form 2 std H units wider than most right control right side...
  209.   TheWth% = (frmEd.Left + frmEd.width + (2 * gHStd) + (2 * gSysMet.wthFrame)) * gTwpsPerPxlX
  210.   '---Make form 2 Std H units taller than lowest control bottom...
  211.   TheHgt% = (frmEd.Top + frmEd.Height + gSysMet.hgtCapBar + (2 * gSysMet.hgtFrame) + 2 * gHStd) * gTwpsPerPxlY
  212.   '---Center Form left to right...
  213.   TheLft% = .5 * (Screen.width - TheWth%)
  214.   '---Center form top to bottom (mostly toward top)...
  215.   TheTop% = .25 * (Screen.Height - TheHgt%)
  216.   '---Do It...
  217.   Autosize.Move TheLft%, TheTop%, TheWth%, TheHgt%
  218. End Sub
  219. Sub PrimeCtls ()
  220.   '---option button...
  221.   opt(0).Value = -1
  222.   '---combo box...
  223.   cbo(0).AddItem "Aerospace"
  224.   cbo(0).AddItem "Automotive"
  225.   cbo(0).AddItem "Consumer"
  226.   cbo(0).AddItem "Energy"
  227.   cbo(0).ListIndex = 0
  228.   '---listbox...
  229.   lst(0).AddItem "Accounting"
  230.   lst(0).AddItem "Advertising"
  231.   lst(0).AddItem "Engineering"
  232.   lst(0).AddItem "Management"
  233.   lst(0).AddItem "Manufacturing"
  234.   lst(0).ListIndex = 0
  235. End Sub
  236.